<?php

namespace app\api\controller;

use app\services\AdviceService;
use support\Request;

class AdviceController
{
    public function add(Request $request)
    {
        try {
            $data = $request->post();
            AdviceService::add($data);
            return ok_rsp('成功');
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function list(Request $request)
    {
        try {
            $page = $request->post('page', 1);
            $length = $request->post('length', 10);

            $data = AdviceService::list($page, $length);
            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function detail(Request $request)
    {
        try {
            $id = $request->post('id');

            $data = AdviceService::detail($id);
            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

}